package com.ycl.mapper;

import com.ycl.pojo.ChatRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface ChatRecordMapper{
    @Select("SELECT * FROM y_chat_chat_record\n" +
            "WHERE (sender = #{sender} AND recipient = #{recipient})\n" +
            "OR (sender = #{recipient} AND recipient = #{sender})\n" +
            "ORDER BY time ASC;\n")
    List<ChatRecord> selectHistory(@Param("sender") String sender,@Param("recipient") String recipient);

    @Insert("INSERT INTO y_chat_chat_record (sender,recipient,text,time) VALUES (#{c.sender}, #{c.recipient}, #{c.text}, #{c.time} )")
    void addMessage(@Param("c") ChatRecord chatRecord);
}
